package com.jr.controller;


import com.jr.entity.Enterprise;
import com.jr.entity.Job;
import com.jr.service.EnterpriseService;
import com.jr.service.UserJobEnterpriseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 企业表
 *
 * @author Snoopy
 * @since 1.0.0 2022-12-31
 */
@RestController
@SuppressWarnings("all")
public class EnterpriseController {
    @Autowired
    private EnterpriseService enterpriseService;
    @Autowired
    private UserJobEnterpriseService userJobEnterpriseService;

    @GetMapping(value = "getEnterprise",produces = "application/json;charset=utf-8")
    public ModelAndView selectEnterprise(int eid,String jobuserattention){
        ModelAndView modelAndView=new ModelAndView();
        Enterprise enterprise=enterpriseService.selectEnterpriseOne(eid);
        modelAndView.addObject("enterprise",enterprise);
        enterprise.setJobuserattention(jobuserattention);
        modelAndView.setViewName("company.jsp");
        return modelAndView;
    }

    @GetMapping(value = "getJobsByEnterprise",produces = "application/json;charset=utf-8")
    public @ResponseBody List<Job> selectJobsByEnterprise(String uid,int eid){

        List<Job> jobList=enterpriseService.selectEnterpriseJobs(eid);

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Map map = new HashMap<String,String>();
        map.put("uid",uid);
        for (Job job:jobList){

            map.put("jid",job.getJid());
            job.setJobuserstatus(enterpriseService.queryStatusById(map));
            job.setJrefreshdatestr(sdf.format(job.getJrefreshdate()));
        }
        return jobList;
    }


}